home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / The World of Computer Software.iso / srcuc.zip / DOSKBUTL.ASM < prev    next >
Assembly Source File  |  1992-05-13  |  7KB  |  230 lines

  1. ;;; -*-Midas-*-
  2. ;;;
  3. ;;;    $Header: /scheme/src/microcode/RCS/doskbutl.asm,v 1.2 1992/05/13 16:49:53 jinx Exp $
  4. ;;;
  5. ;;;    Copyright (c) 1992 Massachusetts Institute of Technology
  6. ;;;
  7. ;;;    This material was developed by the Scheme project at the
  8. ;;;    Massachusetts Institute of Technology, Department of
  9. ;;;    Electrical Engineering and Computer Science.  Permission to
  10. ;;;    copy this software, to redistribute it, and to use it for any
  11. ;;;    purpose is granted, subject to the following restrictions and
  12. ;;;    understandings.
  13. ;;;
  14. ;;;    1. Any copy made of this software must include this copyright
  15. ;;;    notice in full.
  16. ;;;
  17. ;;;    2. Users of this software agree to make their best efforts (a)
  18. ;;;    to return to the MIT Scheme project any improvements or
  19. ;;;    extensions that they make, so that these may be included in
  20. ;;;    future releases; and (b) to inform MIT of noteworthy uses of
  21. ;;;    this software.
  22. ;;;
  23. ;;;    3. All materials developed as a consequence of the use of this
  24. ;;;    software shall duly acknowledge such use, in accordance with
  25. ;;;    the usual standards of acknowledging credit in academic
  26. ;;;    research.
  27. ;;;
  28. ;;;    4. MIT has made no warrantee or representation that the
  29. ;;;    operation of this software will be error-free, and MIT is
  30. ;;;    under no obligation to provide any services, by way of
  31. ;;;    maintenance, update, or otherwise.
  32. ;;;
  33. ;;;    5. In conjunction with products arising from the use of this
  34. ;;;    material, there shall be no use of the name of the
  35. ;;;    Massachusetts Institute of Technology nor of any adaptation
  36. ;;;    thereof in any advertising, promotional, or sales literature
  37. ;;;    without prior written consent from MIT in each case.
  38. ;;;
  39.  
  40. .386
  41. .model small
  42.     .code
  43.  
  44. ;;    Stack on entry to _DOSX_scheme_system_isr
  45. ;;
  46. ;;32    IRETD EFLAGS
  47. ;;28    IRETD CS
  48. ;;24    IRETD EIP
  49. ;;20    CS for next handler in chain
  50. ;;16    EIP for next handler in chain
  51. ;;12    address of modifier mask
  52. ;;8    offset for unshifted table
  53. ;;4    offset for shifted table
  54. ;;0    DS for scan_code to ascii tables
  55.  
  56.     public _DOSX_scheme_system_isr
  57.     public _DPMI_PM_scheme_system_isr
  58.  
  59. _DOSX_scheme_system_isr:
  60. _DPMI_PM_scheme_system_isr:
  61.     pushfd
  62.     call    scheme_system_isr
  63.     jnc    DOSX_scheme_system_dismiss
  64.  
  65. ;; Chain to next handler (flags unmodified)
  66.     popfd
  67.     lea    esp,16[esp]
  68. ;    ret    far
  69.     db    0cbh
  70.  
  71. ;; Dismiss/finish interrupt (update flags)
  72.  
  73. DOSX_scheme_system_dismiss:
  74.     push    eax
  75.     mov    eax,4[esp]        ;updated flags
  76.     mov    40[esp],eax        ;flags to restore
  77.     pop    eax
  78.     popfd
  79.     lea    esp,24[esp]
  80.     iretd        
  81.  
  82. ;;    Stack on entry to _DPMI_scheme_system_isr
  83. ;;
  84. ;;20    CS for next (real mode) handler in chain
  85. ;;16    IP for next (real mode) handler in chain
  86. ;;12    address of modifier mask
  87. ;;8    offset for unshifted table
  88. ;;4    offset for shifted table
  89. ;;0    DS for scan_code to ascii tables
  90.  
  91.     public _DPMI_RM_scheme_system_isr
  92. _DPMI_RM_scheme_system_isr:
  93.     mov    eax,es:28[edi]        ; real mode eax
  94.     xor    edx,edx
  95.     mov    dx,es:32[edi]        ; real mode flags
  96.     push    edx
  97.     call    scheme_system_isr
  98.     jnc    DPMI_scheme_system_dismiss
  99.  
  100. ;; Chain to next real mode handler (flags unmodified)
  101.     lea    esp,4[esp]        ; drop flags
  102.     mov    eax,16[esp]        ; real mode IP (padded to dword)
  103.     mov    es:42[edi],ax
  104.     mov    eax,20[esp]        ; real mode CS (padded to dword)
  105.     mov    es:44[edi],ax
  106.     lea    esp,24[esp]        ; pop args
  107.     iret                ; tell DPMI we're done
  108.  
  109. ;; Dismiss/finish interrupt in real mode (update flags, simulate RM iret)
  110.  
  111. DPMI_scheme_system_dismiss:
  112.     pop    eax            ; updated flags
  113.     mov    es:32[edi],ax
  114.     mov    ax,ds:[esi]        ; real mode IRET ip
  115.     mov    es:42[edi],ax
  116.     mov    ax,ds:2[esi]        ; real mode IRET cs
  117.     mov    es:44[edi],ax
  118.     add    word ptr es:46[edi],6    ; bump real mode sp
  119.     lea    esp,24[esp]        ; pop args
  120.     iret                ; tell DPMI we're done    
  121.  
  122. ;;    Stack on entry to scheme_system_isr
  123. ;;
  124. ;;24    address of modifier mask
  125. ;;20    offset for unshifted table
  126. ;;16    offset for shifted table
  127. ;;12    DS for scan_code to ascii tables
  128. ;;8    Flags to restore/modify
  129. ;;4    EIP for low-level hook (DPMI or DOSX)
  130. ;;0    Old ebp [pushed on entry]
  131. ;;
  132. ;;    Arguments:
  133. ;; AL = scan code
  134. ;; AH = 4fh
  135. ;; CF set
  136. ;;
  137. ;;    Return:
  138. ;; AL = scan code
  139. ;; CF clear if scan code should be ignored (interrupt dismissed).
  140.  
  141. chain_to_next_handler:
  142.     stc                ; set the carry flag
  143.     ret
  144.  
  145. scheme_system_isr:
  146.     cmp    ah,4fh
  147.     jne    chain_to_next_handler
  148.     cmp    al,39h
  149.         ja      chain_to_next_handler
  150.  
  151. ;; process a keystroke
  152.  
  153.     push    ebp
  154.     mov    ebp,esp
  155.         push    eax             ; Preserve accross interrupt
  156.  
  157.         mov     ah,2h           ; Get shift bits
  158.         int     16h             ; Return in AL
  159.         
  160.         push    ecx
  161.         push    edx             ; Preserve regs
  162.         push    es
  163.  
  164.         mov     edx,12[ebp]      ; Segment selector
  165.         push    edx
  166.         pop     es
  167.     
  168.         mov     edx,24[ebp]     ; Modifier mask address
  169.         and     al,es:[edx]     ; Ignore modifiers
  170.         push    eax             ; Save result
  171.         
  172.         mov     ecx,-4[ebp]     ; Scan code + function number
  173.         and     ecx,3fh         ; Only scan code
  174.         mov     edx,20[ebp]     ; Unshifted table offset
  175.         and     eax,47h         ; Shift, ctrl, and CAPS-LOCK mask
  176.         cmp     al,0
  177.         je      index_into_table
  178.         mov     edx,16[ebp]      ; Shifted table offset
  179.  
  180. index_into_table:
  181.         mov     al,es:[edx] [ecx]  ; Get ASCII value
  182.         pop     edx             ; Masked modifier bits
  183.         cmp     al,0            ; Null entries mean chain
  184.         je      abort_translation
  185.  
  186.         bt      edx,2           ; Control set?
  187.         jnc     after_control
  188.         and     al,09fh         ; Clear bits 6 and 5
  189.  
  190. after_control:
  191.         bt      edx,3           ; Alt set?
  192.         jnc     after_meta
  193.         or      al,080h         ; Set bit 8
  194.  
  195. after_meta:
  196.     cmp    al,0f0h        ; M-p ?
  197.     je    abort_translation
  198.         mov     ecx,-4[ebp]     ; Get scan code
  199.  
  200.     cmp    al,0        ; C-Space ?
  201.     jne    after_ctrl_space
  202.     mov    cl,3        ; Fudge scan code
  203.  
  204. after_ctrl_space:
  205.     mov    ch,cl
  206.         mov     cl,al           ; Transfer ASCII value
  207.         
  208.         mov     ah,5h           ; Insert keystroke
  209.         int     16h             ; CH = scan code, CL = ASCII
  210.                                 ; returns AL = 0h if win, 1h if buffer full
  211.  
  212.     and    byte ptr 8[ebp],0feh    ; clear interrupt carry flag
  213.         pop     es
  214.         pop     edx
  215.         pop     ecx
  216.     pop    eax
  217.     pop    ebp
  218.     clc                ; clear our carry flag
  219.     ret
  220.  
  221. abort_translation:
  222.         pop     es
  223.         pop     edx
  224.         pop     ecx
  225.     pop    eax
  226.     pop    ebp
  227.     stc                ; set carry flag
  228.     ret
  229. end
  230.